package cn.haiway.drools.execute.config;

import cn.haiway.drools.execute.service.DroolsExecuteService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Haiway  on 2019/4/18
 */

@Service
@Slf4j
public class RedisMessageSubscriber implements MessageListener {

    @Resource
    DroolsExecuteService droolsExecuteService;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        log.info("received msg:"+message.toString());

        JSONObject jsonObject = JSONObject.parseObject(message.toString());

        if(jsonObject !=null){
            droolsExecuteService.updateKieBase(jsonObject.getString("groupId"),jsonObject.getString("artifactId"),jsonObject.getString("version"));
        }
    }
}

